<template>
    <div class="address-edit">
        <van-field label="收货人姓名" v-model="address.name"></van-field>
        <van-field label="收货人手机号" v-model="address.mobile"></van-field>
        <van-field label="收货人地址" v-model="address.address"></van-field>
        <van-field label="地址标签" v-model="address.tag"></van-field>
        <van-checkbox v-model="address.is_default">默认地址</van-checkbox>
        <van-button block @click="save">修改</van-button>
    </div>
</template>

<script>
import axios from "axios";
export default {
    // DOM 挂载后执行
    created() {
        this.getDetail();
    },
    data() {
        return {
            address: {},
        };
    },
    methods: {
        async getDetail() {
            const res = await axios.get(`/addresses/${this.$route.params.id}`);
            this.address = res.data.data;
        },
        async save() {
            console.log(this.address);
            const data = {
                ...this.address,
                is_default: this.address.is_default ? 1 : 0,
            };
            console.log(data);
            // const res = await axios.put(`/addresses/${this.$route.params.id}`);
            // console.log("res", res);
        },
    },
};
</script>

<style lang="less" scoped>
.address-edit {
    min-height: 100vh;
    height: 100%;
    background-color: #f3f3f3;
    padding-top: 1px;
}
</style>
